package com.ctosb.classviewer.clazz.attr;

import com.ctosb.classviewer.ClassReader;
import com.ctosb.classviewer.clazz.AbstractParse;
import com.ctosb.classviewer.clazz.ClassFile;
import com.ctosb.classviewer.clazz.Parseable;
import com.ctosb.classviewer.clazz.cp.CONSTANT_Utf8_info;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public abstract class Attribute_info extends AbstractParse {

    private short attribute_name_index;
    private int attribute_length;

    @Override
    public Attribute_info parse(ClassReader classReader) {
        this.attribute_length = classReader.readInt();
        doParse(classReader);
        return this;
    }

    public String getAttribute_name() {
        return ((CONSTANT_Utf8_info)getClassFile().getConstant_pool()[attribute_name_index]).getValue();
    }

    protected abstract void doParse(ClassReader classReader);
}
